function cell_fig_vis2(ROI_act,aux_data,nbr_frames,cur_frame_times,pupil_diam,pupil_pos,blink,iframe_times)

names{1}='feedback';
names{2}='playback';
names{3}='feedback.FFM';
names{4}='feedback.LFM';
names{5}='playback.FFM';
names{6}='playback.LFM';

[~,velM,velP_ind,velM_ind,~,~]=get_vel_ind_from_adata(aux_data);
runM=velM_ind(cur_frame_times);
runP=velP_ind(cur_frame_times);
shutterOpen=find(abs(diff(aux_data(1,:)>1))==1);
% Code:
% 1 = feedback
% 2 = playback
% 3 = baseline

if length(nbr_frames)>5
    order=[];
    for xnd=1:length(nbr_frames)
        if nbr_frames(xnd)==20000
            if xnd==length(nbr_frames)
                order(xnd)=3;
            else
                order(xnd)=1;
            end
        else
            order(xnd)=2;
        end
    end
else
    order=[1 2 1 2 3];
end
a=1:length(order);
order(max(a(order==2))+1:end)=3;
nbr_exp=length(order);
nbr_bas=sum(order==3);
bas_exp=[];
for lnd=1:length(nbr_bas)
    bas_exp(lnd)=shutterOpen((nbr_exp*2)-((lnd*2)-1));
end
bas_exp=min(bas_exp);

exp_inds=[];
for fnd=1:length(order)
    [~,ini]=min(abs(cur_frame_times-shutterOpen((fnd*2)-1)));
    [~,fin]=min(abs(cur_frame_times-shutterOpen(fnd*2)));
    exp_inds(fnd,:)=[ini fin];
end

act=psmooth(ROI_act);
baseline=baseline_f(act,cur_frame_times,aux_data,velM_ind,nbr_frames,bas_exp);
raw_act=act/baseline;

stim_id=round(2*aux_data(3,cur_frame_times));
shad=[];
vis_fl=[];
cnt=1;
for bnd=1:length(order)
    if order(bnd)==1
        tmp_runM=runM(exp_inds(bnd,1):exp_inds(bnd,2));
        tmp_stim_id=stim_id(exp_inds(bnd,1):exp_inds(bnd,2));
        for fnd=1:length(tmp_runM)
            if tmp_runM(fnd)==0
                shad(cnt)=0;
                vis_fl(cnt)=0;
                cnt=cnt+1;
            elseif tmp_runM(fnd)==1 & logical(tmp_stim_id(fnd))==0 %feedback
                shad(cnt)=1;
                vis_fl(cnt)=1;
                cnt=cnt+1;
            elseif tmp_runM(fnd)==1 & logical(tmp_stim_id(fnd))==1 %feedback mismatch
                if tmp_stim_id(fnd)==7
                    shad(cnt)=3;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                else
                    shad(cnt)=4;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                end
            end
        end
    elseif order(bnd)==2
        tmp_runM=runM(exp_inds(bnd,1):exp_inds(bnd,2));
        tmp_stim_id=stim_id(exp_inds(bnd,1):exp_inds(bnd,2));
        tmp_runP=runP(exp_inds(bnd,1):exp_inds(bnd,2));
        for fnd=1:length(tmp_runM)
            if logical(tmp_stim_id(fnd))==0 & tmp_runM(fnd)==0 & tmp_runP(fnd)==0 | logical(tmp_stim_id(fnd))==1 & tmp_runM(fnd)==0 & tmp_runP(fnd)==0
                shad(cnt)=0;
                vis_fl(cnt)=0;
                cnt=cnt+1;
            elseif logical(tmp_stim_id(fnd))==1 & tmp_runM(fnd)==0 & tmp_runP(fnd)==1
                if tmp_stim_id(fnd)==7
                    shad(cnt)=5;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                else
                    shad(cnt)=6;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                end
            elseif logical(tmp_stim_id(fnd))==0 & tmp_runM(fnd)==0 & tmp_runP(fnd)==1
                shad(cnt)=2;
                vis_fl(cnt)=1;
                cnt=cnt+1;
            elseif logical(tmp_stim_id(fnd))==0 & tmp_runM(fnd)==1 & tmp_runP(fnd)==1
                shad(cnt)=1;
                vis_fl(cnt)=1;
                cnt=cnt+1;
            elseif logical(tmp_stim_id(fnd))==0 & tmp_runM(fnd)==1 & tmp_runP(fnd)==0 | logical(tmp_stim_id(fnd))==1 & tmp_runM(fnd)==1 & tmp_runP(fnd)==0
                shad(cnt)=3;
                vis_fl(cnt)=0;
                cnt=cnt+1;
            elseif logical(tmp_stim_id(fnd))==1 & tmp_runM(fnd)==1 & tmp_runP(fnd)==1
                if tmp_stim_id(fnd)==7
                    shad(cnt)=3;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                else
                    shad(cnt)=4;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                end
            end
        end
    end
end

vis_fl(length(vis_fl):length(runM))=0;
speed_ref=velM(cur_frame_times);

delta=[];
for ind=1:size(pupil_pos,2)-1
    dx=abs(pupil_pos(1,ind)-pupil_pos(1,ind+1));
    dy=abs(pupil_pos(2,ind)-pupil_pos(2,ind+1));
    delta(ind)=sqrt(dx^2+dy^2);
    if ind==size(pupil_pos,2)-1
        delta(ind+1)=delta(ind);
    end
end

ipsonsets=[];
for ind=1:length(cur_frame_times)
    [~,tmp]=min(abs(iframe_times-cur_frame_times(ind)));
    ipsonsets(ind)=tmp;
end
pupil_diam=pupil_diam(ipsonsets);
delta=delta(ipsonsets);
blink=blink(ipsonsets);

% shad_full=downsample(shad_full,10);
% vis_fl_full=downsample(vis_fl_full,10);
% runM=downsample(runM,10);
% speed_ref=downsample(speed_ref,10);
% pupil_diam=downsample(pupil_diam,10);
% delta=downsample(delta,10);
% blink=downsample(blink,10);
% ROI_act=downsample(ROI_act,10);

col{1}=[0.8 0.8 0.8];
col{2}=[0.3 0.7 0.3];
col{3}=[1 0.5 0];
col{4}=[1 1 0.5];
col{5}=[0.9 0.2 0.2];
col{6}=[0 1 1];

figure('color','w');
set(gcf,'position',[14         867        3813         129]);
set(gca,'Position',[0.01 0.01 0.99 0.99])
hold on
for hnd=1:6
    area([1:length(shad)],50*(shad==hnd),'facecolor',col{hnd},'linestyle','none')
end
hold on
plot(runM/5,'color','red','LineWidth',1.5)
plot((vis_fl/5)+0.3,'color',[0 0.3 0],'LineWidth',1.5)
plot((speed_ref*10)+0.6,'m');
plot(pupil_diam/(max(pupil_diam)*2)+4,'b','LineWidth',1.2)
plot(delta/(max(delta)*2)+3.6,'b','LineWidth',1.2)
plot(blink/(max(blink)*2)+3,'b','LineWidth',1.2)
plot(raw_act+0.1,'color','k','LineWidth',1.5)
ylim([0 4.5])
xlim([0 length(runM)+800])
axis off
drawnow
legend(names)